package com.wlw.service;
import java.util.List;

import org.hibernate.Query;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wlw.entity.City;
import com.wlw.entity.Scenery;

import edu.xjsoft.base.service.DefaultEntityManager;

@Service
@Transactional
public class CityService extends DefaultEntityManager<City> {
	/**
	 * 热门推荐：
	 * SELECT c.name,c.brief FROM tb_Gonglue g,tb_city c WHERE g.id=c.id ORDER BY g.zanCount DESC LIMIT 7;
	 */
	public List<City> hotCities() {
		String hql = "select c from Gonglue g,City c where g.id=c.id order by g.zanCount DESC";
//		List<City> cities = getEntityDao().find(hql);
		Query query = getEntityDao().createQuery(hql);
		query.setFirstResult(0);
		query.setMaxResults(7);
		List<City> cities = query.list();
		return cities;
	}
	/**
	 * 目的地分类（国内）
	 */
	public List<City> homeCityClass() {
		String hql = "select c from City c where c.foreign.country=? order by c.province.direction";
		List<City> cities = getEntityDao().find(hql, "中国");
		return cities;
	}
	/**
	 * 目的地分类（国外）
	 */
	public List<City> foreignCityClass(){
		String hql = "select c from City c where c.foreign.country!=? order by c.foreign.continent";
		List<City> cities = getEntityDao().find(hql, "中国");
		return cities;
	}
	/**
	 * 按目的地：春夏秋冬
	 */
	//春
	public List<City> chunCities(){
		String hql = "select c from City c where c.prettyMonth = ? or c.prettyMonth = ? or c.prettyMonth = ?";
//		List<City> cities = getEntityDao().find(hql, 2,3,4);
		Query query = getEntityDao().createQuery(hql, 2,3,4);
		query.setFirstResult(0);
		query.setMaxResults(3);
		List<City> cities = query.list();
		return cities;
	}
	//夏
	public List<City> xiaCities(){
		String hql = "select c from City c where c.prettyMonth = ? or c.prettyMonth = ? or c.prettyMonth = ?";
//		List<City> cities = getEntityDao().find(hql, 5,6,7);
		Query query = getEntityDao().createQuery(hql, 5,6,7);
		query.setFirstResult(0);
		query.setMaxResults(3);
		List<City> cities = query.list();
		return cities;
	}
	//秋
	public List<City> qiuCities(){
		String hql = "select c from City c where c.prettyMonth = ? or c.prettyMonth = ? or c.prettyMonth = ?";
//		List<City> cities = getEntityDao().find(hql, 8,9,10);
		Query query = getEntityDao().createQuery(hql, 8,9,10);
		query.setFirstResult(0);
		query.setMaxResults(3);
		List<City> cities = query.list();
		return cities;
	}
	//冬
	public List<City> dongCities(){
		String hql = "select c from City c where c.prettyMonth = ? or c.prettyMonth = ? or c.prettyMonth = ?";
//		List<City> cities = getEntityDao().find(hql, 11,12,1);
		Query query = getEntityDao().createQuery(hql, 11,12,1);
		query.setFirstResult(0);
		query.setMaxResults(3);
		List<City> cities = query.list();
		return cities;
	}
	//查询城市
	public List<City> searchCities(String name){
		String hql = "select c from City c where c.name like ?";
		List<City> cities = getEntityDao().find(hql, "%"+name+"%");
		return cities;
	}
	//查询本省的城市：
	public List<City> localCities(String name){
		String hql = "select c from City c where c.province.name = ?";
		List<City> cities = getEntityDao().find(hql, name);
		return cities;
	}
}
